<!DOCTYPE html><html lang="zh-Hans"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"><meta name="description" content="CocoaPods创建和发布"><meta name="keywords" content="CocoaPods"><meta name="author" content="kyren"><meta name="copyright" content="kyren"><title>CocoaPods创建和发布 | Kyren's Blog</title><link rel="shortcut icon" href="/melody-favicon.ico"><link rel="stylesheet" href="/css/index.css?version=1.9.0"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/font-awesome@latest/css/font-awesome.min.css?version=1.9.0"><meta name="format-detection" content="telephone=no"><meta http-equiv="x-dns-prefetch-control" content="on"><link rel="dns-prefetch" href="https://cdn.jsdelivr.net"><link rel="dns-prefetch" href="https://hm.baidu.com"><script>var _hmt = _hmt || [];
(function() {
  var hm = document.createElement("script");
  hm.src = "https://hm.baidu.com/hm.js?cf87fcdbd9ab7cf93d894f7c219ae78f";
  var s = document.getElementsByTagName("script")[0]; 
  s.parentNode.insertBefore(hm, s);
})();</script><meta http-equiv="Cache-Control" content="no-transform"><meta http-equiv="Cache-Control" content="no-siteapp"><script src="https://v1.hitokoto.cn/?encode=js&amp;charset=utf-8&amp;select=.footer_custom_text" defer></script><script>var GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"search.xml","languages":{"hits_empty":"找不到您查询的内容:${query}"}},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  hexoVersion: '6.2.0'
} </script><meta name="generator" content="Hexo 6.2.0"></head><body><i class="fa fa-arrow-right" id="toggle-sidebar" aria-hidden="true"></i><div id="sidebar" data-display="true"><div class="toggle-sidebar-info text-center"><span data-toggle="切换文章详情">切换站点概览</span><hr></div><div class="sidebar-toc"><div class="sidebar-toc__title">目录</div><div class="sidebar-toc__progress"><span class="progress-notice">你已经读了</span><span class="progress-num">0</span><span class="progress-percentage">%</span><div class="sidebar-toc__progress-bar"></div></div><div class="sidebar-toc__content"><ol class="toc"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%80%E3%80%81%E5%88%9B%E5%BB%BA%E7%A7%81%E6%9C%89pod"><span class="toc-number">1.</span> <span class="toc-text">一、创建私有pod</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BA%8C%E3%80%81%E4%BD%BF%E7%94%A8Trunk%E5%88%9B%E5%BB%BA%E5%AE%98%E6%96%B9CocoaPod"><span class="toc-number">2.</span> <span class="toc-text">二、使用Trunk创建官方CocoaPod</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%B8%89-%E3%80%81%E8%B8%A9%E8%BF%87%E7%9A%84%E4%B8%80%E4%BA%9B%E5%9D%91%E5%A4%87%E5%BF%98"><span class="toc-number">3.</span> <span class="toc-text">三 、踩过的一些坑备忘</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%A4%A7%E4%BD%93%E6%B5%81%E7%A8%8B"><span class="toc-number">4.</span> <span class="toc-text">大体流程</span></a></li></ol></div></div><div class="author-info hide"><div class="author-info__avatar text-center"><img src="https://avatars.githubusercontent.com/u/5827823?v=4"></div><div class="author-info__name text-center">kyren</div><div class="author-info__description text-center">huluo的技术博客</div><div class="follow-button"><a target="_blank" rel="noopener" href="https://github.com/huluo666">Follow Me</a></div><hr><div class="author-info-articles"><a class="author-info-articles__archives article-meta" href="/archives"><span class="pull-left">文章</span><span class="pull-right">239</span></a><a class="author-info-articles__tags article-meta" href="/tags"><span class="pull-left">标签</span><span class="pull-right">41</span></a><a class="author-info-articles__categories article-meta" href="/categories"><span class="pull-left">分类</span><span class="pull-right">29</span></a></div><hr><div class="author-info-links"><div class="author-info-links__title text-center">Links</div><a class="author-info-links__name text-center" target="_blank" rel="noopener" href="http://192.168.2.212:9090/">Jira</a><a class="author-info-links__name text-center" target="_blank" rel="noopener" href="http://192.168.2.212:8090/">Confluence</a><a class="author-info-links__name text-center" target="_blank" rel="noopener" href="http://bloc.leniugame.com/">Leniu</a></div></div></div><div id="content-outer"><div class="no-bg" id="top-container"><div id="page-header"><span class="pull-left"> <a id="site-name" href="/">Kyren's Blog</a></span><i class="fa fa-bars toggle-menu pull-right" aria-hidden="true"></i><span class="pull-right menus">   <a class="site-page" href="/">主页</a><a class="site-page" href="/essay">随笔</a><a class="site-page" href="/archives">归档</a><a class="site-page" href="/tags">标签</a><a class="site-page" href="/categories">分类</a><a class="site-page" href="/about">关于</a></span><span class="pull-right"><a class="site-page social-icon search"><i class="fa fa-search"></i><span> 搜索</span></a></span></div><div id="post-info"><div id="post-title">CocoaPods创建和发布</div><div id="post-meta"><time class="post-meta__date"><i class="fa fa-calendar" aria-hidden="true"></i> 2016-04-13</time><span class="post-meta__separator">|</span><i class="fa fa-inbox post-meta__icon" aria-hidden="true"></i><a class="post-meta__categories" href="/categories/iOS/">iOS</a></div></div></div><div class="layout" id="content-inner"><article id="post"><div class="article-container" id="post-content"><h3 id="一、创建私有pod"><a href="#一、创建私有pod" class="headerlink" title="一、创建私有pod"></a>一、创建私有pod</h3><p><strong>1.克隆项目到本地</strong></p>
<p>cd进入本地某个目录 ，从github上clone下项目</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">$ cd xxx/xxx/file</span><br><span class="line">$ git clone https://github.com/huluo666/HJDefaultsCache.git</span><br></pre></td></tr></table></figure>

<p>cd进入项目目录</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ cd xxx/xxx/HJDefaultsCache</span><br></pre></td></tr></table></figure>

<p><strong>2.打tag</strong></p>
<p>本地项目是没有tag的，给项目加入一个tag。以便pod能自动识别</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">git tag 1.0.0  //git tag -m &quot;注释&quot; 0.0.2﻿</span><br><span class="line">git push --tags</span><br><span class="line">git push origin master</span><br></pre></td></tr></table></figure>



<p><strong>3.创建podspec文件</strong></p>
<figure class="highlight sh"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">$ pod spec create  https://github.com/huluo666/HJDefaultsCache</span><br></pre></td></tr></table></figure>

<p>编辑<code>.podspec</code>文件</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">Pod::Spec.new do |s|</span><br><span class="line"><span class="meta prompt_">  #</span><span class="language-bash">项目名称</span></span><br><span class="line">  s.name         = &quot;HJDefaultsCache&quot;</span><br><span class="line"><span class="meta prompt_">  #</span><span class="language-bash">版本号</span></span><br><span class="line">  s.version      = &quot;1.0.0&quot;			  //版本号</span><br><span class="line"><span class="meta prompt_">  #</span><span class="language-bash">对开源项目的描述</span></span><br><span class="line">  s.summary      = &quot;为NSUserDefaults设置默认值&quot;</span><br><span class="line">  s.description  = &lt;&lt;-DESC</span><br><span class="line">   					为NSUserDefaults设置默认值</span><br><span class="line">                   DESC</span><br><span class="line"><span class="meta prompt_">  #</span><span class="language-bash">开源项目的首页</span></span><br><span class="line">  s.homepage     = &quot;https://github.com/huluo666/HJDefaultsCache&quot;</span><br><span class="line"><span class="meta prompt_">  #</span><span class="language-bash">开源协议</span></span><br><span class="line">  s.license = &#123; :type =&gt; &#x27;MIT&#x27;, :text =&gt; &lt;&lt;-LICENSE</span><br><span class="line">                   Copyright 2016</span><br><span class="line">                   Permission is granted to...</span><br><span class="line">                 LICENSE</span><br><span class="line">               &#125;</span><br><span class="line">               </span><br><span class="line">  s.author             = &#123; &quot;H罗&quot; =&gt; &quot;huluo666@126.com&quot; &#125;</span><br><span class="line"><span class="meta prompt_">  #</span><span class="language-bash">适用于ios7及以上版本</span></span><br><span class="line">  s.platform     = :ios, &quot;7.0&quot; </span><br><span class="line">  s.source       = &#123; :git =&gt; &quot;https://github.com/huluo666/HJDefaultsCache.git&quot;, :tag =&gt; &quot;#&#123;s.version&#125;&quot; &#125;</span><br><span class="line"><span class="meta prompt_">  #</span><span class="language-bash">源文件，这个就是供第三方使用的源文件</span></span><br><span class="line">  s.source_files  = &quot;Classes&quot;, &quot;HJDefaultsCache/**/*.&#123;h,m&#125;&quot;</span><br><span class="line">  s.exclude_files = &quot;Classes/Exclude&quot;</span><br><span class="line"><span class="meta prompt_">  #</span><span class="language-bash">使用的是ARC</span></span><br><span class="line">  s.requires_arc = true</span><br><span class="line"><span class="meta prompt_">  # </span><span class="language-bash">s.resources = <span class="string">&quot;Resources/*.png&quot;</span></span></span><br><span class="line"><span class="meta prompt_">  # </span><span class="language-bash">s.dependency <span class="string">&quot;JSONKit&quot;</span>, <span class="string">&quot;~&gt; 1.4&quot;</span></span></span><br><span class="line">end</span><br></pre></td></tr></table></figure>

<p>注意: </p>
<ul>
<li><p>1、s.version应和tag的版本一致.先push该文件之后,再push –tags</p>
</li>
<li><p>2、将源代码放置在固定的文件夹下,同时修改s.source</p>
</li>
</ul>
<p>修改好的<code>podspec</code>文件记得上传同步</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">git add HJDefaultsCache.podspec</span></span><br><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">git commit -am <span class="string">&quot;add HJDefaultsCache.podspec 注释”</span></span></span><br><span class="line"><span class="meta prompt_">$ </span><span class="language-bash"><span class="string">git push -u origin master</span></span></span><br></pre></td></tr></table></figure>

<p>最后，在你项目的Podfile里面加入这个第三方库的地址 <code>pod install</code>。</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pod &#x27;HJDefaultsCache&#x27;, :git =&gt; &#x27;https://github.com/huluo666/HJDefaultsCache.git&#x27;</span><br></pre></td></tr></table></figure>



<h3 id="二、使用Trunk创建官方CocoaPod"><a href="#二、使用Trunk创建官方CocoaPod" class="headerlink" title="二、使用Trunk创建官方CocoaPod"></a>二、使用Trunk创建官方CocoaPod</h3><p>要想使用Trunk服务，首先你需要注册自己的电脑。这很简单，只要你指明你的邮箱地址（spec文件中的）和名称即可。</p>
<ul>
<li><p>1.第一次使用,注册  <code>$ pod trunk register 793633193@qq.com &#39;huluo666&#39;</code></p>
</li>
<li><p>2.收到邮件激活后，检查是否注册成功 <code>pod trunk me</code></p>
</li>
</ul>
<p>ps:当然，如果你的pod是由多人维护的，你也可以添加其他维护者</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">pod trunk add-owner ARAnalytics kyle@cocoapods.org</span></span><br></pre></td></tr></table></figure>

<ul>
<li><p>3 .验证podspec文件是否有误 <code>pod spec lint Test.podspec</code></p>
<p>   成功 <code>Test.podspec passed validation</code>.</p>
</li>
<li><p>4.push pod spec文件</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">pod trunk push Test.podspec</span></span><br></pre></td></tr></table></figure></li>
</ul>
<p>等待部署成功。</p>
<h3 id="三-、踩过的一些坑备忘"><a href="#三-、踩过的一些坑备忘" class="headerlink" title="三 、踩过的一些坑备忘"></a>三 、踩过的一些坑备忘</h3><p><code>-WARN  | [iOS] license: Unable to find a license file</code></p>
<p>参考官网 <a target="_blank" rel="noopener" href="https://guides.cocoapods.org/syntax/podspec.html#license">https://guides.cocoapods.org/syntax/podspec.html#license</a></p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">s.license = &#123; :type =&gt; &#x27;MIT&#x27;, :text =&gt; &lt;&lt;-LICENSE</span><br><span class="line">                  Copyright 2016</span><br><span class="line">                  Permission is granted to...</span><br><span class="line">                LICENSE</span><br><span class="line">              &#125;</span><br></pre></td></tr></table></figure>

<p><code>WARN  | source: The version should be included in the Git tag.</code></p>
<p>本地podspec文件和github上的tag要一致</p>
<p>其它命令</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">//删除Tag</span><br><span class="line">git tag -d v1.0.0</span><br><span class="line">git push origin :refs/tags/v1.0.0</span><br></pre></td></tr></table></figure>





<h3 id="大体流程"><a href="#大体流程" class="headerlink" title="大体流程"></a>大体流程</h3><p><strong>1、创建描述文件</strong></p>
<p><code>pod spec create  https://github.com/huluo666/NetWorkMonitorView</code></p>
<ul>
<li>若没有设置tag会有提示,执行下面命令，重新进行第一步即可</li>
</ul>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line">​```</span><br><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">git tag -a 1.0.0 -m <span class="string">&quot;Tag release 1.0.0&quot;</span></span></span><br><span class="line"><span class="meta prompt_">$ </span><span class="language-bash">git push --tags</span></span><br><span class="line">​```</span><br></pre></td></tr></table></figure>

<p><strong>2.验证描述文件</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pod spec lint yourPodName.podspec</span><br></pre></td></tr></table></figure>

<p><strong>3.trunk 发布</strong></p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">pod trunk push  //如果有警告  pod trunk push --allow-warnings </span><br></pre></td></tr></table></figure>



<p>参考</p>
<p><a target="_blank" rel="noopener" href="https://guides.cocoapods.org/making/private-cocoapods.html">https://guides.cocoapods.org/making/private-cocoapods.html</a></p>
<p><a target="_blank" rel="noopener" href="http://www.voidcn.com/blog/bluefish89/article/p-3673616.html">http://www.voidcn.com/blog/bluefish89/article/p-3673616.html</a></p>
<p><a target="_blank" rel="noopener" href="http://useyourloaf.com/blog/creating-a-cocoapod/">http://useyourloaf.com/blog/creating-a-cocoapod/</a></p>
</div></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="mailto:undefined">kyren</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://huluo666.gitee.io/2016/04/13/CocoaPods创建和发布/">http://huluo666.gitee.io/2016/04/13/CocoaPods创建和发布/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://huluo666.gitee.io">Kyren's Blog</a>！</span></div></div><div class="post-meta__tag-list"><a class="post-meta__tags" href="/tags/CocoaPods/">CocoaPods</a></div><nav id="pagination"><div class="prev-post pull-left"><a href="/2016/04/14/m3u8%E6%96%87%E4%BB%B6%E4%B8%8B%E8%BD%BD/"><i class="fa fa-chevron-left">  </i><span>Mac 网页视频下载</span></a></div><div class="next-post pull-right"><a href="/2016/04/12/CocoaPods%E5%AE%89%E8%A3%85%E5%92%8C%E4%BD%BF%E7%94%A8%E6%95%99%E7%A8%8B/"><span>CocoaPods安装和使用教程</span><i class="fa fa-chevron-right"></i></a></div></nav></div></div><footer><div class="layout" id="footer"><div class="copyright">&copy;2022 By kyren</div><div class="framework-info"><span>驱动 - </span><a target="_blank" rel="noopener" href="http://hexo.io"><span>Hexo</span></a><span class="footer-separator">|</span><span>主题 - </span><a target="_blank" rel="noopener" href="https://github.com/Molunerfinn/hexo-theme-melody"><span>Melody</span></a></div><div class="footer_custom_text">hitokoto</div><div class="busuanzi"><script async src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><span id="busuanzi_container_page_pv"><i class="fa fa-file"></i><span id="busuanzi_value_page_pv"></span><span></span></span></div></div></footer><i class="fa fa-arrow-up" id="go-up" aria-hidden="true"></i><script src="https://cdn.jsdelivr.net/npm/animejs@latest/lib/anime.min.js"></script><script src="https://cdn.jsdelivr.net/npm/jquery@latest/dist/jquery.min.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@latest/dist/jquery.fancybox.min.js"></script><script src="https://cdn.jsdelivr.net/npm/velocity-animate@latest/velocity.min.js"></script><script src="https://cdn.jsdelivr.net/npm/velocity-ui-pack@latest/velocity.ui.min.js"></script><script src="/js/utils.js?version=1.9.0"></script><script src="/js/fancybox.js?version=1.9.0"></script><script src="/js/sidebar.js?version=1.9.0"></script><script src="/js/copy.js?version=1.9.0"></script><script src="/js/fireworks.js?version=1.9.0"></script><script src="/js/transition.js?version=1.9.0"></script><script src="/js/scroll.js?version=1.9.0"></script><script src="/js/head.js?version=1.9.0"></script><script src="/js/search/local-search.js"></script><script>if(/Android|webOS|iPhone|iPod|iPad|BlackBerry/i.test(navigator.userAgent)) {
  $('#nav').addClass('is-mobile')
  $('footer').addClass('is-mobile')
  $('#top-container').addClass('is-mobile')
}</script><div class="search-dialog" id="local-search"><div class="search-dialog__title" id="local-search-title">本地搜索</div><div id="local-input-panel"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章"></div></div></div><hr><div id="local-search-results"><div id="local-hits"></div><div id="local-stats"><div class="local-search-stats__hr" id="hr"><span>由</span> <a target="_blank" rel="noopener" href="https://github.com/wzpan/hexo-generator-search" style="color:#49B1F5;">hexo-generator-search</a>
 <span>提供支持</span></div></div></div><span class="search-close-button"><i class="fa fa-times"></i></span></div><div class="search-mask"></div></body></html>